package com.demo.inner;

/**
 * created by lanxinghua@2dfire.com on 2020/2/13
 * 企业内部开发：身份认证
 * https://work.weixin.qq.com/api/doc/90000/90135/91020
 */
public class InnerAuthenticationDemo extends InnerBaseService{

    public static void main(String[] args) throws Exception{
//        getUserInfoByCodeAndAccessToken1();
        getUserInfoByCodeAndAccessToken2();
    }

    /**------------------------- 网页授权登录   -------------------------**/
    /**
     * 授权链接  通过code换取code
     * https://open.weixin.qq.com/connect/oauth2/authorize?appid=CORPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect
     * 前：https://open.weixin.qq.com/connect/oauth2/authorize?appid=wwd276de90ff82e1e3&redirect_uri=https%3a%2f%2fchenxingxing.51vip.biz%2f&response_type=LL6VlbceFLgKsSR38xM9MUWw-4nivIZ0UoZS_Qq7Bdc&scope=snsapi_base&state=STATE#wechat_redirect
     * 后：https://chenxingxing.51vip.biz/?code=eTrMxa-_afrQ8JsK-rnmSJdBZhCvqalYQ4ZSDZHjHP8&state=STATE
     *
     * code获取用户信息：响应结果
     * {
     *     "UserId":"ChenXingXing",
     *     "DeviceId":"d93b8209-bf41-4d15-9bd2-136138799a03",
     *     "errcode":0,
     *     "errmsg":"ok"
     * }
     */
    public static void getUserInfoByCodeAndAccessToken1() throws Exception{
        String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?";
        String code = "ww5E0nxAJcyJYC-ew0v8H9s82xsDCTQzQiUMP0AG3Ys";
        String param = String.format("access_token=%s&code=%s", accessToken, code);
        String result = wxCpService.get(url, param);
        System.out.println(result);
    }


    /**------------------------- 扫码授权登录   -------------------------**/
    /**
     * 扫码登录回掉url:https://chenxingxing.51vip.biz/?code=kEHwWoSSVgVAFbTJZgceIxQV2JZxL4-oZvz0llCNigU&state=STATE&appid=wwd276de90ff82e1e3
     * 响应结果：{"UserId":"ChenXingXing","DeviceId":"","errcode":0,"errmsg":"ok"}
     */
    public static void getUserInfoByCodeAndAccessToken2() throws Exception{
        String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?";
        String code = "kEHwWoSSVgVAFbTJZgceIxQV2JZxL4-oZvz0llCNigU";
        String param = String.format("access_token=%s&code=%s", accessToken, code);
        String result = wxCpService.get(url, param);
        System.out.println(result);
    }
}
